package servlet;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspWriter;

/**
 * Servlet implementation class TestServlet
 */
@WebServlet("/TestServlet")
public class TestServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * Default constructor.
	 */
	JspWriter out;

	public TestServlet(JspWriter outputStream) {
		// TODO Auto-generated constructor stub
		out = outputStream;
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		out.println("<strong>FROM TestServlet.doGet()</strong>");
	}

	public void printSomething(JspWriter out) throws IOException {
		out.println("<h2>h2 printSomething() using jspWriter as parameter</h2>");
		this.out.println("printSomething() using JspWriter specified in instantiation of TestServlet");
	}

	public String returnSomething(String input) {
		return "you entered \"input\"";
	}

	public String getTable() {
		String table = "<br/> this table was obtained through a method that could have been in any class <br/> <table>";
		table += "<tr><td>r1c1</td><td>r1c2</td></tr>";
		table += "<tr><td>r2c1</td><td>r2c2</td></tr>";
		table += "</table>";
		return table;
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
		// TODO Auto-generated method stub
	}

}
